package com.example.ymm.modules1.controller.hl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.ymm.model.CommonResult;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.controller.BaseController;
import com.example.ymm.modules1.entity.hl.yw.YwApprove;
import com.example.ymm.modules1.entity.hl.yw.YwDept;
import com.example.ymm.modules1.entity.ms.DEmployee;
import com.example.ymm.modules1.entity.my.user.DbApprovalLog;
import com.example.ymm.modules1.query.DbApprovalLogQueryCriteria;
import com.example.ymm.modules1.query.hl.YwDeptQueryCriteria;
import com.example.ymm.modules1.query.hl.YwMoneyAffirmLogCountQueryCriteria;
import com.example.ymm.modules1.service.dto.heng.*;
import com.example.ymm.modules1.service.dto.ms.CountMoneyUserDto;
import com.example.ymm.modules1.service.hl.*;
import com.example.ymm.modules1.service.user.DbApprovalLogService;
import com.example.ymm.modules1.service.xft.XftService;
import com.example.ymm.util.DateKit;
import com.example.ymm.util.RedisUtil;
import com.example.ymm.util.UtilValidate;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/hl/heng/yw/approval")
@Tag(name = "hl 业务抽成审批接口")
@Slf4j
@CrossOrigin
public class YwApprovalController extends BaseController {

    @Autowired
    DbApprovalLogService dbApprovalLogService;
    @Autowired
    YwApproveService ywApproveService;
    @Autowired
    YwMoneyAffirmLogService ywMoneyAffirmLogService;
    @Autowired
    YwUserService ywUserService;
    @Autowired
    XftService xftService;
    @Autowired
    DknTrialItemService dknTrialItemService;
    @Autowired
    private YwDeptService ywDeptService;
    @Autowired
    RedisUtil redisUtil;


    @Schema( name =  "业务员提成 已审批列表")
    @PostMapping("/ywApprovalList")
    public CommonResult ywApprovalList(DbApprovalLogQueryCriteria criteria, YmPageDto ymPage) {
        try {
            String userName = getUserName();
            String userRole = getUserRole();
            String userId = getUserId();

            boolean is_show_all=false;//是否拥有查看所有数据的权限
            if ("manage".equals(userRole)) {
                is_show_all=true;
            }
            if(userName.equals("杨柳")|| userName.equals("张爱君")||userName.equals("邵琪")||userName.equals("庄嫚艺")){
                is_show_all=true;
            }
            if (!is_show_all) {
                criteria.setAllUserIds(userId);
            }
            //查询是否经理
            if (!"manage".equals(userRole)) {
                YwDeptQueryCriteria ywDeptQueryCriteria = new YwDeptQueryCriteria();
                ywDeptQueryCriteria.setManageUserName(userName);
                List<YwDept> ywDepts = ywDeptService.queryAll(ywDeptQueryCriteria);
                if(UtilValidate.isNotEmpty(ywDepts)) {
                    YwDept ywDept = ywDepts.get(0);
                    List<String>  deptNoIn=new ArrayList<>();
                    deptNoIn.add(ywDept.getDeptNo());
                    System.out.println("---deptNoIn:"+deptNoIn);
//                criteria.setDeptNoIn(deptNoIn);
//                criteria.setAllUserIds(null);
                }
            }
            TableList<DbApprovalLog> list = dbApprovalLogService.list(criteria, ymPage);
            return CommonResult.success(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "表部汇总列表")
    @PostMapping("/ywDeptTotalList")
    public CommonResult ywDeptTotalList(DbApprovalLogQueryCriteria criteria, YmPageDto ymPage) {
        try {
            List<String> salesmanDeptNos=new ArrayList<>();
            /**
             * HL02-2  迪卡侬营销部
             * HL02-3  OEM营销部
             */
            String userName = getUserName();
            String userRole = getUserRole();

            DEmployee userInfo = ywUserService.getUserInfoToSlave2(userName);
            if(UtilValidate.isNotEmpty(userInfo)){
                String dname = userInfo.getDname();
                //迪卡侬和OEM营销部
                if(dname.equals("迪卡侬营销部")||dname.equals("OEM营销部")){
                    salesmanDeptNos.add("HL02-2");
                    salesmanDeptNos.add("HL02-3");
                    salesmanDeptNos.add("HL08-0-7");//东莞恒丽

                }else{
                    salesmanDeptNos.add(userInfo.getDtid());
                }
            }
            if(UtilValidate.isNotEmpty(criteria.getMonth())){
                String month = criteria.getMonth();
                String start=month+"-01 00:00:00";
                String end = DateKit.getNextMonthStartDate(start);
                criteria.setStartTime(start);
                criteria.setEndTime(end);
            }
            if(UtilValidate.isNotEmpty(criteria.getDeptNo())){
                String[] split = criteria.getDeptNo().split(",");
                for(String deptNo:split){
                    salesmanDeptNos.add(deptNo);
                }
            }
            if(UtilValidate.isEmpty(criteria.getStatus())){
                criteria.setStatus(2);
            }
            criteria.setDeptNoIn(salesmanDeptNos);

            TableList<DbApprovalLog> list = dbApprovalLogService.ywDeptTotalList(criteria, ymPage);
            return CommonResult.success(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 审批详情")
    @PostMapping("/getCountDeptTotalLog_biao")
    public CommonResult getCountDeptTotalLog_biao(YwMoneyAffirmLogCountQueryCriteria criteria) {
            try {
                List<String> salesmanDeptNos=new ArrayList<>();

                String userName = getUserName();
                String userRole = getUserRole();
                if (!"manage".equals(userRole)) {
                    DEmployee userInfo = ywUserService.getUserInfoToSlave2(userName);
                    if(UtilValidate.isNotEmpty(userInfo)){
                        String dname = userInfo.getDname();
                        //迪卡侬和OEM营销部
                        if(dname.equals("迪卡侬营销部")||dname.equals("OEM营销部")){
                            salesmanDeptNos.add("HL02-2");
                            salesmanDeptNos.add("HL02-3");
                            salesmanDeptNos.add("HL08-0-7");//东莞恒丽
                        }else{
                            salesmanDeptNos.add(userInfo.getDtid());
                        }
                    }
                }
                if(UtilValidate.isNotEmpty(criteria.getMonth())){
                    String month = criteria.getMonth();
                    String start=month+"-01 00:00:00";
                    String end = DateKit.getNextMonthStartDate(start);
                    criteria.setStartTime(start);
                    criteria.setEndTime(end);
                }
                if(UtilValidate.isNotEmpty(criteria.getDeptNo())){
                    String[] split = criteria.getDeptNo().split(",");
                    for(String deptNo:split){
                        salesmanDeptNos.add(deptNo);
                    }
                }

                criteria.setSalesmanDeptNoIn(salesmanDeptNos);
                List<CountMoneyUserDto> list = ywMoneyAffirmLogService.getCountDeptTotalLog_biao(criteria);

                return CommonResult.success(list);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return CommonResult.error(e.getMessage());
            }
        }



    @Schema( name =  "业务员提成 审批详情")
    @PostMapping("/ywApprovalDetailByApproveNo")
    public CommonResult ywApprovalDetailByApproveNo(String approveNo) {
        try {
            DbApprovalLog approveNo1 = dbApprovalLogService.getApproveNo(approveNo);
            YwApprove byApproveNo = ywApproveService.findByApproveNo(approveNo);
            approveNo1.setApprove(byApproveNo);
            return CommonResult.success(approveNo1);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "业务员提成 审批详情")
    @PostMapping("/ywApprovalDetail")
    public CommonResult ywApprovalDetail(String approvalLogId) {
        try {
            DbApprovalLog approvalLog = dbApprovalLogService.getById(approvalLogId);
            return CommonResult.success(approvalLog);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

//    @Schema( name =  "业务员提成 管理员强制审批")
//    @PostMapping("/ywManageDelete")
//    public CommonResult ywManageDelete(String approveNo) {
//        try {
//            ywApproveService.approveCancel(approveNo);
//            return CommonResult.success();
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//            return CommonResult.error(e.getMessage());
//        }
//    }


    @Schema( name =  "业务员提成 发起前查看审批人")
    @PostMapping("/ywApprovalCreateView")
    public CommonResult ywApprovalCreateView(@RequestParam String approvalName,String title) {
        try {
            // "业务员提成审批"
            ApprovalCreateViewDto dto = ywApproveService.ywApprovalCreateView(approvalName,title);
            return CommonResult.success(dto);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 查看审批进度")
    @PostMapping("/ywApprovalLogView")
    public CommonResult ywApprovalLogView(String approveNo) {
        try {
            ApprovalCreateViewDto dto = ywApproveService.ywApprovalLogView(approveNo);
            return CommonResult.success(dto);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 审批提起")
    @PostMapping("/ywApprovalSubmit")
    public CommonResult ywApprovalSubmit(@RequestBody YwApproveCreateDto dto) {
        try {


            ApproveRespond approveRespond = ywApproveService.ywApprovalSubmit(dto);
            return CommonResult.success(approveRespond);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 文件 审批提起")
    @PostMapping("/ywApprovalFileSubmit")
    public CommonResult ywApprovalFileSubmit(YwApproveCreateK3Dto dto) {
        try {
            ApproveRespond approveRespond = ywApproveService.ywApprovalFileSubmit(dto);
            return CommonResult.success(approveRespond);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 审批通过")
    @PostMapping("/ywApprovalPass")
    public CommonResult ywApprovalPass(YwApprovaPassDto dto) {
        try {
            ywApproveService.ywApprovalPass(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 审批驳回")
    @PostMapping("/ywApprovalBack")
    public CommonResult ywApprovalBack(YwApprovaPassDto dto) {
        try {
            ywApproveService.ywApprovalBack(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "业务员提成 申请人撤回")
    @PostMapping("/ywApprovalCancel")
    public CommonResult ywApprovalCancel(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            ywApproveService.ywApprovalCancel(approveNo);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 申请人撤回")
    @PostMapping("/ywApprovalRemove")
    public CommonResult ywApprovalRemove(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            ywApproveService.ywApprovalRemove(approveNo);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "业务员提成 按钮显示")
    @PostMapping("/ywApprovalShow")
    public CommonResult ywApprovalShow(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            ApprovalButtonShowDto dto = dbApprovalLogService.approveButtonShow(approveNo);
            return CommonResult.success(dto);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "审批单号提成统计")
    @PostMapping("/countApproverNoTotal")
    public CommonResult countApproverNoTotal(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            YwMoneyAffirmLogCountQueryCriteria criteria=new YwMoneyAffirmLogCountQueryCriteria();
            criteria.setApproverNo(approveNo);
            List<CountMoneyUserDto> dtos = ywMoneyAffirmLogService.countApproverNoTotal(criteria);
            return CommonResult.success(dtos);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }



    @Schema( name =  "添加审批评论")
    @PostMapping("/addYwComment")
    public CommonResult addYwComment(YwApprovaPassDto dto) {
        try {
            if(UtilValidate.isEmpty(dto.getApproveNo())){
                return CommonResult.error("审批编号不能为空！");
            }
            ywApproveService.addYwComment(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }






    @Schema( name =  "配送费 审批提起")
    @PostMapping("/ywPostageSubmit")
    public CommonResult ywPostageSubmit(@RequestBody YwPostageCreateDto dto) {
        try {
            ApproveRespond approveRespond = ywApproveService.ywPostageSubmit(dto);
            return CommonResult.success(approveRespond);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "配送费 审批通过")
    @PostMapping("/ywPostagePass")
    public CommonResult ywPostagePass(YwApprovaPassDto dto) {
        try {
            ywApproveService.ywPostagePass(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "配送费 审批驳回")
    @PostMapping("/ywPostageBack")
    public CommonResult ywPostageBack(YwApprovaPassDto dto) {
        try {
            ywApproveService.ywPostageBack(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "配送费 申请人撤回")
    @PostMapping("/ywPostageCancel")
    public CommonResult ywPostageCancel(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            ywApproveService.ywPostageCancel(approveNo);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "查询审批表格item数据")
    @PostMapping("/getYwItemList")
    public CommonResult getYwItemList(@Parameter(name = "数据主键") @RequestParam(required = true) String approveNo) {
        try {
            List<JSONObject> itemDataList = dknTrialItemService.getItemDataList(approveNo);
            return CommonResult.success(itemDataList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "排除数据")
    @PostMapping("/addExcludeData")
    public CommonResult addExcludeData(@RequestBody YwExcuteCreateDto dto) {
        try {
            dknTrialItemService.addExcludeData(dto);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "查询排除数据")
    @PostMapping("/getExcludeDataList")
    public CommonResult getExcludeDataList(@RequestParam String approvalName) {
        try {
            List<JSONObject> excludeDataList = dknTrialItemService.getExcludeDataList(approvalName);
            return CommonResult.success(excludeDataList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "删除排除数据")
    @PostMapping("/removeExcludeData")
    public CommonResult removeExcludeData(String orderNo) {
        try {
            dknTrialItemService.removeExcludeData(orderNo);
            return CommonResult.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    /**
     * batchSendYwXftQuery 和 batchSendYwXftSubmit 两者算法要保持一致
     * @param criteria0
     * @return
     */

    @Schema( name =  "推送薪福通前进行查询")
    @PostMapping("/batchSendYwXftQuery")
    public CommonResult batchSendYwXftQuery(DbApprovalLogQueryCriteria criteria0) {
        try {

            List<String> deptName=new ArrayList<>();
            deptName.add("OEM营销部");
            deptName.add("钟营销部");
            deptName.add("时俱佳营销部");
            deptName.add("钢表营销组");
            // 部门名称，部门编号
            Map<String,String> map=new LinkedHashMap<>();
            map.put("OEM营销部","HL02-2,HL02-3,HL08-0-7"); //迪卡侬,OEM营销部,东莞恒丽
            map.put("钟营销部","HL02-1"); //钟营销部
            map.put("时俱佳营销部","HL02-7"); //钟营销部
            map.put("钢表营销组","HL02-4-1"); //钟营销部


            Date now=new Date();
            Map<String,List<ImportXftDataDto>> arr_list=new LinkedHashMap<>();

            String month =null;
            if(UtilValidate.isEmpty(criteria0.getMonth())){
                month =DateKit.dateFormat(now, "yyyy-MM")+"-01";
            }else{
                month =criteria0.getMonth();
            }
            Set<Map.Entry<String, String>> entries = map.entrySet();
            for (Map.Entry<String, String> entry : entries) {
                String depName = entry.getKey();
                String value = entry.getValue();

                List<String> salesmanDeptNos = Arrays.asList(value.split(","));

                YwMoneyAffirmLogCountQueryCriteria criteria=new YwMoneyAffirmLogCountQueryCriteria();

                String start=month+" 00:00:00";
                String end = DateKit.getNextMonthStartDate(start);
                criteria.setStartTime(start);
                criteria.setEndTime(end);

                criteria.setSalesmanDeptNoIn(salesmanDeptNos);
                List<CountMoneyUserDto> list = ywMoneyAffirmLogService.getCountDeptTotalLog_biao(criteria);
                List<ImportXftDataDto> data_list=new ArrayList<>();

                for (CountMoneyUserDto countMoneyUserDto : list) {
                    String userType = countMoneyUserDto.getUserType();
                    String userName = countMoneyUserDto.getUserName();
                    //钟部要结算经理抽成,其他不用

//                    if("manage_user".equals(userType)&&"钟营销部".equals(depName)){
//                        ImportXftDataDto manageDto=new ImportXftDataDto();
//                        manageDto.setUserType(userType);
//                        manageDto.setDeptName(depName);
//                        manageDto.setUserName(userName);
//                        manageDto.setUserPrice(countMoneyUserDto.getUserPrice());
//                        manageDto.setApproveNo(month+"钟部经理抽成");
//                        data_list.add(manageDto);
//                    }
//                    if("merchandiser_user".equals(userType)||"receiver_user".equals(userType)||"introduce_user".equals(userType)){
//                        ImportXftDataDto userDto=new ImportXftDataDto();
//                        userDto.setUserType(userType);
//                        userDto.setDeptName(depName);
//                        userDto.setUserName(userName);
//                        userDto.setUserPrice(countMoneyUserDto.getUserPrice());
//                        userDto.setApproveNo(approvalLog.getApproveNo());
//                        data_list.add(userDto);
//                    }

                    String passApproveNo=null;
                    if(UtilValidate.isNotEmpty(userName)){
                        DbApprovalLogQueryCriteria c2=new DbApprovalLogQueryCriteria();
                        c2.setUserName(userName);
                        c2.setStartTime(start);
                        c2.setEndTime(end);
                        passApproveNo = dbApprovalLogService.getPassApproveNoByUserName(c2);
                    }

                    ImportXftDataDto userDto=new ImportXftDataDto();
                    userDto.setUserType(userType);
                    userDto.setDeptName(depName);
                    userDto.setUserName(userName);
                    userDto.setUserPrice(countMoneyUserDto.getUserPrice());
                    if(!userType.equals("ji_jing")&&!userType.equals("manage_user")){
                        if(UtilValidate.isNotEmpty(passApproveNo)){
                            userDto.setApproveNo(passApproveNo);
                        }
                    }

                    data_list.add(userDto);
                }

                for (ImportXftDataDto importXftDataDto : data_list) {
                    importXftDataDto.setApproveType("业务员抽成审批");
                }

                if(UtilValidate.isNotEmpty(data_list)){
                    arr_list.put(depName,data_list);
                }

            }
            return CommonResult.success(arr_list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "推送薪福通前-确认推送")
    @PostMapping("/batchSendYwXftSubmit")
    public CommonResult batchSendYwXftSubmit(@RequestBody List<SubmitXftDataDto> arr_list) {
        try {

            Date now=new Date();
            String month =DateKit.dateFormat(now, "yyyy-MM");
            List<ImportXftDataDto> data_list=new ArrayList<>();

            for (SubmitXftDataDto countMoneyUserDto : arr_list) {
                String userType = countMoneyUserDto.getUserType();
                String userName = countMoneyUserDto.getUserName();
                String deptName = countMoneyUserDto.getDeptName();
                //钟部要结算经理抽成,其他不用

                if("manage_user".equals(userType)&&"钟营销部".equals(deptName)){

                    countMoneyUserDto.setApproveNo(month+"钟部经理抽成");
                    ImportXftDataDto dto=new ImportXftDataDto();
                    BeanUtils.copyProperties(countMoneyUserDto,dto);
                    if(UtilValidate.isNotEmpty(countMoneyUserDto.getTotalPrice())){
                        dto.setUserPrice(countMoneyUserDto.getTotalPrice());
                    }
                    data_list.add(dto);
                }
                if("merchandiser_user".equals(userType)||"receiver_user".equals(userType)||"introduce_user".equals(userType)){

                    ImportXftDataDto dto=new ImportXftDataDto();
                    BeanUtils.copyProperties(countMoneyUserDto,dto);
                    if(UtilValidate.isNotEmpty(countMoneyUserDto.getTotalPrice())){
                        dto.setUserPrice(countMoneyUserDto.getTotalPrice());
                    }
                    data_list.add(dto);
                }
            }

            ImportJsonDataDto dto=new ImportJsonDataDto();
            dto.setList(data_list);
            dto.setType("业务员抽成审批");
            xftService.importJsonData(dto);
            redisUtil.set("xft_push:"+month,month);
            try{
                String jsonString = JSONArray.toJSONString(arr_list);
                redisUtil.set("xft_push:list:"+month,jsonString);
            }catch (Exception e) {
                log.error(e.getMessage(), e);
            }
            return CommonResult.success(data_list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }


    @Schema( name =  "查询推送按钮控制")
    @PostMapping("/batchSendYwXftBtn")
    public CommonResult batchSendYwXftBtn(DbApprovalLogQueryCriteria criteria0){
        try {
            String month =null;
            Date now=new Date();

            if(UtilValidate.isEmpty(criteria0.getMonth())){
                month = DateKit.dateFormat(now, "yyyy-MM");
            }else{
                String s = criteria0.getMonth();//2025-08-01
//                month = s.substring(0,s.length()-3); //这个控制就不要了，否则删redis还来找我
                month = s;
            }

            String v = redisUtil.getString("xft_push:" + month);
            return CommonResult.success(v);
        }catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

    @Schema( name =  "查询推送记录")
    @PostMapping("/batchSendYwXftLogs")
    public CommonResult batchSendYwXftLogs(DbApprovalLogQueryCriteria criteria0){
        try {

            Set<String> keys = redisUtil.keys("xft_push:list:*");
            Map<String,Object> map=new LinkedHashMap<>();
            for (String key : keys) {
                String string = redisUtil.getString(key);
                JSONArray jsonArray = JSONArray.parseArray(string);
                map.put(key,jsonArray);
            }
            return CommonResult.success(map);
        }catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResult.error(e.getMessage());
        }
    }

}
